package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysProduct;
import com.eos.orm.mybatis.model.SysUser;

public class UpdateProductTypeAction extends AbstractBaseAction {
	private static final long serialVersionUID = -1154884283015192577L;
	private Integer productId;
	private String productName;
	private String oldProductName;
	private String productDesc;
	
	public void setProductId(Integer productId) {
		this.productId = productId;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public void setOldProductName(String oldProductName) {
		this.oldProductName = oldProductName;
	}

	public void setProductDesc(String productDesc) {
		this.productDesc = productDesc;
	}

	@Override
	public String execute()  {
		try {
			if(null == productId || productId.intValue() ==0){
				statusCode = "300";
				message = "参数错误, 修改品名信息失败!";
			}else{
				SysProductBusinessService spbs = new SysProductBusinessService();
				SysProduct product = new SysProduct();
				if(!oldProductName.equals(productName)){
					product.setDealFlag(ConstantTool.DEAL_FALG_OK);
					product.setStatus(ConstantTool.STATUS_OK);
					product.setProductName(productName);
					List<SysProduct> pList = spbs.getSysProductExample(product);
					if(null != pList && pList.size() > 0){
						statusCode = "300";
						message = "保存失败, 输入的品名已经存在!";
						return SUCCESS;
					}
				}
				SysUser user = (SysUser)getSession().getAttribute("SysUser");
				int userId = user.getId();
				product = new SysProduct();
				product.setId(productId);
				product.setProductDesc(productDesc);
				product.setProductName(productName);
				product.setUpdateUserId(userId+"");
				product.setModifyTime(ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss"));
				String exeStatus = spbs.updateSysProductPKSelective(product);
				if("SUCCESS".equals(exeStatus)){
					statusCode = "200";
					message = "修改品名信息成功!";
				}else{
					statusCode = "300";
					message = "系统繁忙, 修改品名信息失败!";
				}
			}
		} catch (Exception e) {
		    e.printStackTrace();
		    statusCode = "300";
		    message = "系统异常,修改品名信息失败!";
		}
		return SUCCESS;
	}
}
